package com.testfileupload.uploadimg.design.combination.definesafe;

public class Client {
    public static void main(String[] args) {
        //创建一个根节点
        Composite composite = new Composite();
        composite.doSomething();
        //创建一个树枝节点
        Composite branch = new Composite();
        //创建一个叶子节点
        Leaf leaf = new Leaf();
        //建立整体
        composite.add(branch);
        branch.add(leaf);
    }
    //通过递归遍历树
    public static void display(Composite root){
        for (Componet componet :root.getChild()){
            if (componet instanceof Leaf){
                componet.doSomething();
            }else {
                display((Composite) componet);
            }
        }
    }
}
